package com.huangfuyi.common.entity.webreturn;

import com.huangfuyi.common.exceptions.EException;

public class R<T> {

    private boolean success;

    private int code;

    private String message;

    private T data;

    private int pageNo;

    private int pageSize;

    private int total;

    public R(boolean success, int code, String message, T data, int pageNo, int pageSize, int total) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.total = total;
    }

    public static <T> R<T> ok() {
        return ok(null);
    }

    public static <T> R<T> ok(T data) {
        return ok(data, 0, 0, 0);
    }

    public static <T> R<T> ok(T data, int pageNum, int pageSize, int total) {
        return new R<>(true, 0, "操作成功", data, pageNum, pageSize, total);
    }

    public static <T> R<T> error() {
        return error(new EException("服务异常。"));
    }

    public static <T> R<T> error(EException e) {
        return new R<>(false, e.getCode(), e.getMessage(), null, 0, 0, 0);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }
}
